package cmd

import (
	// "fmt"
	// "github.com/chromedp/cdproto/network"
	// "github.com/chromedp/chromedp"
	"github.com/spf13/cobra"
	// "strings"
)

func init() {
	rootCmd.AddCommand(searchCmd)
}

var searchCmd = &cobra.Command{
	Use:              string(Search),
	Short:            "Make keyword search shopes of dp",
	Long:             `Make keyword search shopes of dp`,
	TraverseChildren: true,
	Run: func(cmd *cobra.Command, args []string) {
		slog.Debugf("in search isDebug=>%v", isDebug)
		slog.Debugf("city => %s", cityLookup[cityName])
		slog.Debugf("args => %s", args)
		if len(args) == 0 {
			slog.Error("need search keyword. use: dp search 咬不得")
			return
		}
		keyword := args[0]

		// NewRunner().
		// 	AddListener(func(resp *network.Response) {
		// 		if strings.Contains(resp.URL, "/queryqrcodestatus") {
		// 			fmt.Println("等待扫码登录...")
		// 		}
		// 	}).
		// 	Navigate(`https://account.dianping.com/pclogin`).
		// 	OutputQRCode().
		// 	BlockUtil(func(resp *network.Response) bool {
		// 		success := strings.Contains(resp.URL, "userinfo?uuid")
		// 		if success {
		// 			fmt.Println("扫码成功...")
		// 		}
		// 		return success
		// 	}).
		// 	SaveCredential().
		// 	// Display().
		// 	LoadCredential().
		// 	SearchByKeyworOld(cityLookup[cityName], keyword).
		// 	Run()

		NewRunner().
			LoadCredentialFromFile().
			// SearchByKeyworOld(cityLookup[cityName], keyword).
			SearchByKeyword(cityLookup[cityName], keyword).
			DumpSearchResult().
			SearchResultReset().
			// Wait(15).
			Run()
	},
}
